package com.company.woye.lcl.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.company.woye.Inventory.entity.DetailsEntity;
import com.company.woye.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class LCLDetailListviewAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private Context mContext;
    private List<DetailsEntity> detailsEntities;

    public LCLDetailListviewAdapter(Context context, List<DetailsEntity> detailsEntities) {
        this.inflater = LayoutInflater.from(context);
        this.mContext = context;
        this.detailsEntities = detailsEntities;
    }

    @Override
    public int getCount() {
        return detailsEntities.size();
    }

    @Override
    public Object getItem(int position) {
        return detailsEntities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHodler = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_adapter_lcl_detail, parent, false);
            viewHodler = new ViewHolder(convertView);
            convertView.setTag(viewHodler);
        } else {
            viewHodler = (ViewHolder) convertView.getTag();
        }
        if (detailsEntities.size()>0){
            DetailsEntity detailsEntity = detailsEntities.get(position);
            viewHodler.tvInventoryItemDetailBW.setText(detailsEntity.getBw());
            viewHodler.tvInventoryItemDetailColor.setText(detailsEntity.getColor());
            viewHodler.tvInventoryItemDetailCountry.setText(detailsEntity.getCountry());
            viewHodler.tvInventoryItemDetailDBH.setText(detailsEntity.getDBH());
            viewHodler.tvInventoryItemDetailId.setText(detailsEntity.getIntID());
            viewHodler.tvInventoryItemDetailNumber.setText(detailsEntity.getNumber());
            viewHodler.tvInventoryItemDetailOrder.setText(detailsEntity.getOrderNo());
            viewHodler.tvInventoryItemDetailPO.setText(detailsEntity.getPO());
            viewHodler.tvInventoryItemDetailSc.setText(detailsEntity.getSc());
            viewHodler.tvInventoryItemDetailSh.setText(detailsEntity.getSh());
            viewHodler.tvInventoryItemDetailStylesort.setText(detailsEntity.getStyleSort());
            viewHodler.tvInventoryItemDetailTXM.setText(detailsEntity.getTXM());
        }

        return convertView;
    }



    static
    class ViewHolder {
        @BindView(R.id.tv_inventory_item_detail_Id)
        TextView tvInventoryItemDetailId;
        @BindView(R.id.tv_inventory_item_detail_TXM)
        TextView tvInventoryItemDetailTXM;
        @BindView(R.id.tv_inventory_item_detail_BW)
        TextView tvInventoryItemDetailBW;
        @BindView(R.id.tv_inventory_item_detail_Number)
        TextView tvInventoryItemDetailNumber;
        @BindView(R.id.tv_inventory_item_detail_order)
        TextView tvInventoryItemDetailOrder;
        @BindView(R.id.tv_inventory_item_detail_PO)
        TextView tvInventoryItemDetailPO;
        @BindView(R.id.tv_inventory_item_detail_DBH)
        TextView tvInventoryItemDetailDBH;
        @BindView(R.id.tv_inventory_item_detail_Country)
        TextView tvInventoryItemDetailCountry;
        @BindView(R.id.tv_inventory_item_detail_Color)
        TextView tvInventoryItemDetailColor;
        @BindView(R.id.tv_inventory_item_detail_sh)
        TextView tvInventoryItemDetailSh;
        @BindView(R.id.tv_inventory_item_detail_sc)
        TextView tvInventoryItemDetailSc;
        @BindView(R.id.tv_inventory_item_detail_stylesort)
        TextView tvInventoryItemDetailStylesort;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
